package com.chaos.eurekaproducer.utils;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

/**
 * @author liaopeng
 * @title: MyExceptionThreadFactory
 * @projectName eureka-producer
 * @description: TODO
 * @date 2021/5/25上午10:22
 */
public class MyExceptionThreadFactory implements ThreadFactory {

    Thread.UncaughtExceptionHandler handler;
    public MyExceptionThreadFactory(Thread.UncaughtExceptionHandler handler) {
        this.handler=handler;
    }
    @Override
    public Thread newThread(Runnable r) {
        Thread thread = Executors.defaultThreadFactory().newThread(r);
        thread.setUncaughtExceptionHandler(handler);
        return thread;
    }
}




